iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 3
0
DevOps

.NET Core 專案持續整合與部署系列 第 3

.NET Core CLI:建立方案與專案

  • 分享至 

  • xImage
  •  

先附上嘗試的指令與其紀錄,晚點再補上文字說明與心得。

TL;DR

透過建立新的 Solution、加入專案、到建置、測試,暸解如何透過 dotnet 命令列去執行。

正文

建立方案

# ~
$ mkdir dotnet-sln
$ cd dotnet-sln

# ~/dotnet-sln
$ dotnet new sln
$ ls
dotnet-sln.sln

建立專案

# ~/dotnet-sln
$ mkdir WebProj
$ cd WebProj

# ~/dotnet-sln/WebProj
$ dotnet new mvc
The template "ASP.NET Core Web App (Model-View-Controller)" was created successfully.
This template contains technologies from parties other than Microsoft, see https://aka.ms/aspnetcore-template-3pn-210 for details.

Processing post-creation actions...
Running 'dotnet restore' on /Users/fntsr/Projects/dotnet-sln/WebProj/WebProj.csproj...
  Restore completed in 522.21 ms for /Users/fntsr/dotnet-sln/WebProj/WebProj.csproj.

Restore succeeded.

$ ls
Controllers                  Properties                   appsettings.Development.json obj
Models                       Startup.cs                   appsettings.json             wwwroot
Program.cs                   Views                        mvc-proj.csproj

$ cd ..

# ~/dotnet-sln
$ dotnet sln add WebProj/WebProj.csproj
Project `WebProj/WebProj.csproj` added to the solution.

建置專案

# ~/dotnet-sln
$ dotnet build
Microsoft (R) Build Engine version 16.2.32702+c4012a063 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 51.63 ms for /Users/fntsr/dotnet-sln/WebProj/WebProj.csproj.
  WebProj -> /Users/fntsr/dotnet-sln/WebProj/bin/Debug/netcoreapp2.2/WebProj.dll
  WebProj -> /Users/fntsr/dotnet-sln/WebProj/bin/Debug/netcoreapp2.2/WebProj.Views.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:04.68

建立測試專案

# ~/dotnet-sln
$ mkdir WebProj.Tests
$ cd WebProj.Tests

# ~/dotnet-sln/WebProj.Tests
$ dotnet new xunit
The template "xUnit Test Project" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on /Users/fntsr/dotnet-sln/WebProj.Tests/WebProj.Tests.csproj...
  Restore completed in 21.5 sec for /Users/fntsr/dotnet-sln/WebProj.Tests/WebProj.Tests.csproj.

Restore succeeded.

$ ls
UnitTest1.cs         WebProj.Tests.csproj obj

$ dotnet add reference ../WebProj/WebProj.csproj
# Reference `..\WebProj\WebProj.csproj` added to the project.

$ cd ..

# ~/dotnet-sln/
$ dotnet sln add WebProj.Tests/WebProj.Tests.csproj
Project `WebProj.Tests/WebProj.Tests.csproj` added to the solution.

$ dotnet build
Microsoft (R) Build Engine version 16.2.32702+c4012a063 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 38.94 ms for /Users/fntsr/Projects/dotnet-sln/WebProj/WebProj.csproj.
  Restore completed in 395.7 ms for /Users/fntsr/Projects/dotnet-sln/WebProj.Tests/WebProj.Tests.csproj.
  WebProj -> /Users/fntsr/dotnet-sln/WebProj/bin/Debug/netcoreapp2.2/WebProj.dll
  WebProj -> /Users/fntsr/dotnet-sln/WebProj/bin/Debug/netcoreapp2.2/WebProj.Views.dll
  WebProj.Tests -> /Users/fntsr/dotnet-sln/WebProj.Tests/bin/Debug/netcoreapp2.2/WebProj.Tests.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:02.61

執行測試

# ~/dotnet-sln/
$ dotnet test
Test run for /Users/fntsr/Projects/dotnet-sln/WebProj.Tests/bin/Debug/netcoreapp2.2/WebProj.Tests.dll(.NETCoreApp,Version=v2.2)
Microsoft (R) Test Execution Command Line Tool Version 16.2.0-preview-20190606-02
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...

Test Run Successful.
Total tests: 1
     Passed: 1
 Total time: 1.6001 Seconds

上一篇
.NET Core CLI:安裝
下一篇
.NET Core CLI:管理 NuGet 套件
系列文
.NET Core 專案持續整合與部署31
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言